#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 205;

int n, n2;
int a[N];
int dp[N][N];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  n2 = n * 2;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, n) a[i + n] = a[i];
  rep(len, 2, n) {
    rep(l, 1, n2 - len) {
      int r = l + len - 1;
      rep(i, l, r - 1) {
        dp[l][r] =
            max(dp[l][r], dp[l][i] + dp[i + 1][r] + a[l] * a[i + 1] * a[r + 1]);
      }
    }
  }
  int ans = 0;
  rep(i, 1, n) ans = max(ans, dp[i][i + n - 1]);
  cout << ans;
  return 0;
}